<?php
        /* 搜索页面
         * 
         *  */
        require_once '../inc/fuzzysearch.php';
        require_once '../inc/section.php';
                
        $searchNew=$_POST["searchNew"];
        /* $searchNew='孤独'; */
       
        
        /* 书评展示 */
        function showReview($reviews){
            if ($reviews>0)
            {
                $showReview="";
                for ($i=0; $i<count($reviews); $i++){
                    $uName=$reviews["$i"]["uName"];
                    $reviewId=$reviews["$i"]["reviewId"];
                    $head=$reviews["$i"]["head"];
                    $title=$reviews["$i"]["title"];
                    $reviewTime=$reviews["$i"]["reviewtime"];
                    $content=$reviews["$i"]["content"];
                    $good=$reviews["$i"]["good"];
                    $labelId=$reviews["$i"]["labelId"];
                    $contentcut=cutstr($content, '200');
                    $showReview.=<<<html
                                <div class="showReview">
                                    <div class="reWriter">
                                        <div>
                                            <img src="../image/head/$head" >
                                        </div>
                                        <span>
                                            $uName
                                        </span>
                                    </div><!--/reWriter  -->
                                    <div class="review">
                                        <a href="review.php?reviewId=$reviewId"><span class="title">$title</span></a>
                                       <div class="content"><span>$contentcut</span></div>
                                        <div class="good">
                                                <img src="../image/searchLove.png">
                                                <span>$good</span>
                                        </div>
                                                    
html;
                    if ($labelId!=1) {
                        $showlabel="";
                        $label=getLabelId($labelId);
                        $labelName=$label["label"];
                        $showReview.=<<<html
                                <div class="label">
                                   <span>  # $labelName </span>
                                </div>
html;
                        
                    }
                    $showReview.=<<<html
                                <div class="time">
                                        <span>发布时间：$reviewTime<span>
                                </div>
                                    </div><!--/review  -->
                                </div><!--/showReview  -->
html;
                    
                }
                echo $showReview;
            }
        } 
        
        
        /*  书本展示*/
        function showBook($books){
            if ($books>0)
            {
                $showBook="";
                for ( $i=0; $i<count($books); $i++){
                    $bookPic=$books["$i"]["bookPic"];
                    $bookName=$books["$i"]["bookName"];
                    $bookId=$books["$i"]["bookId"];
                    $introduction=$books["$i"]["introduction"];
                    $writer=$books["$i"]["writer"];
                    
                    $showBook.=<<<html
                                <div class="showBook">
					               <div  class="bookimg">
					                   <img alt="" src="../image/book/$bookPic" >
					               </div>
                                   <div class="booknew">
                                       <a href="book.php?bookId=$bookId"><span class="match">
                                                                            书名： $bookName
                                       </span></a>
                                       <br>
                                       <span class="match">
                                                                            作者： $writer
                                       </span><br>
                                       <span>
                                                                            简介： $introduction
                                       </span>  <br>
                                   </div>
 					           </div>  <!--showBook  -->
html;
                }
                echo $showBook;
            }
        }
        
        /* 展示作者 */
        function showWriter($writers){
            if ($writers>0) 
            {
                $showWriter="";
                for ($i=0; $i<count($writers); $i++){
                    $writerId=$writers["$i"]["writerId"];
                    $writerName=$writers["$i"]["writer"];
                    $writerhead=$writers["$i"]["wrihead"];
                    $lifetime=$writers["$i"]["lifetime"];
                    $cutlife=cutstr($lifetime, '350');
                    $works=writerWork($writerId);
                    
                    $showWriter.=<<<html
                    <div class="showWriter">
                                <div  class="writerimg">
					                 <img alt="" src="../image/wrihead/$writerhead" >
					            </div>
                                   <div class="booknew">
                                       <span class="match">
                                                                                                                      姓名：&nbsp; $writerName
                                       </span><br>
                                       <div  class="cutlife">
                                           <span>
                                                                                                                        简介：&nbsp; $cutlife
                                            </span>
                                       </div><br>
                                       <span>
                                                                                                                    作品：&nbsp;.
html;
                                            for ($i=0; $i<count($works); $i++){
                                                     $workName=$works["$i"]["workName"];
                                                     $showWriter.=<<<html
                                                                                                                                                                    《 $workName 》.
html;
                                                 }
                                            $showWriter.=<<<html
                                       </span>
                                   </div>  
                    </div><!-- /showWriter -->
html;
                    
                }
                    echo $showWriter;
            }
        }
       
?>
<html>
	<title>搜索页-阅读记</title>
	<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="../css/search.css">
	<script src="../script/search.js"></script>
	</head>
	<body>
		 
		<div class="DIV">
			<div class="searchDIV">
				
				<img src=../image/logoBottom.png />	
				<div class="search">					
					<form action="search.php"  method="post" name="searchForm" id="searchForm"  onsubmit="return checksearchForm()">
						<input type="text"  class="fuzzy" placeholder="搜索或跳转至..." name="searchNew" value="<?php echo $searchNew; ?>" />
						<button class="fuzzyBtn" type="submit"></button>
		  			</form>
				</div>
			</div><!-- /searchDIV -->
			<div class="mainDIV">
				<div class="main">
					<?php 
					/* 查找作者 */
					   $writers=fuzzyWriter($searchNew);
					   $rs4=showWriter($writers);
					   echo $rs4;
					/* 查找书本 */
					   $books=fuzzyBook($searchNew);
					   $rs1=showBook($books);
					   echo $rs1;

					   
					  
					   /* 查找相关书评 */
					   $reviews=fuzzyReview($searchNew);
					   $rs2=showReview($reviews);
					   echo $rs2;
					   
					   /* 查找标签 */
					   $reviews=fuzzyLabel($searchNew);
					   $rs3=showReview($reviews);
					   echo $rs3;
					   

 					?> 
	
				<div class="end">
					<span>已无更多查询内容，如想要更多不一样的内容，请自行百度百科（baike.baidu.com）</span>
				</div>
				</div><!-- /main -->
			</div><!--/mainDIV  -->
				<?php 
				require_once '../style/footer.php';
				?>
		</div><!-- /DIV -->
	</body>
</html>